import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";

import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import path from "path";
import AutoImport from "unplugin-auto-import/vite";

export default defineConfig(({ mode, command }) => {
  // const env = loadEnv(mode, process.cwd());
  // const { VITE_APP_ENV } = env;
  return {
    // base: VITE_APP_ENV === "production" ? "/" : "/",

    plugins: [
      vue(),
      AutoImport({
        imports: ["vue", "vue-router"],
      }),
      createSvgIconsPlugin({
        // 指定需要缓存的图标文件夹
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons/svg")],
        // 指定 symbolId 的格式
        symbolId: "icon-[dir]-[name]",
      }),
    ],
    resolve: {
      // https://cn.vitejs.dev/config/#resolve-alias
      alias: {
        // 设置路径
        "~": path.resolve(__dirname, "./"),
        // 设置别名
        "@": path.resolve(__dirname, "./src"),
      },
      // https://cn.vitejs.dev/config/#resolve-extensions
      extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
    },
    // vite 代理
    server: {
      port: 80,
      host: true,
      open: true,
      proxy: {
        // https://cn.vitejs.dev/config/#server-proxy
        "/dev-api": {
          // target: "http://172.20.10.13:8080",
          target: "http://192.168.1.40:8080",
          // target: "https://app.hnlyzy.cn:6443/prod-api/",
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api/, ""),
        },
        "/dev-api2": {
          target: "http://sph-api.atguigu.cn",
          // target: 'https://heimahr.itheima.net',
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api2/, ""),
        },
      },
    },
  };
});
